<template>
  <div>
    <div class="whole">
      <van-nav-bar title="标题" class="city-head">
        <template #left>
          <van-icon name="arrow-left" color="white" @click="$router.back()" />
        </template>
        <template #title>
          <div class="city-title">{{ community }}</div>
        </template>
      </van-nav-bar>

      <!-- 轮播图 -->
      <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
        <van-swipe-item
          v-for="(item, index) in houseInfo.houseImg"
          :key="index"
        >
          <img :src="'http://liufusong.top:8080' + item" alt="" />
        </van-swipe-item>
      </van-swipe>

      <div class="houseDetail-info">
        <h3>{{ houseInfo.title }}</h3>
        <div class="chara">
          <span class="hao" v-for="(item, index) in houseInfo.tags" :key="index"
            >{{ item }}
          </span>
        </div>
        <div class="housePrice">
          <div class="price-item">
            <p>{{ houseInfo.price }}<span>/月</span></p>
            <div>租金</div>
          </div>
          <div class="price-item" style="margin: 0 8px">
            <p>{{ houseInfo.roomType }}</p>
            <div>房型</div>
          </div>
          <div class="price-item">
            <p>{{ houseInfo.size }}平米</p>
            <div>面积</div>
          </div>
        </div>

        <div class="houseChara">
          <div class="houseChara-item">
            <div><span class="">装修：</span>精装</div>
            <div><span class="">楼层：</span>高楼层</div>
          </div>
          <div class="houseChara-item">
            <div><span class="">朝向：</span>东</div>
            <div><span class="">类型：</span>普通住宅</div>
          </div>
        </div>
      </div>

      <div class="houseDetail-map">
        <div class="mapTitle">小区：<span>天山星城</span></div>
        <div id="container"></div>
      </div>

      <div class="housePei">
        <div class="peititle">房屋配套</div>
        <ul class="">
          <li class="">
            <p><i class="iconfont icon-yigui"></i></p>
            衣柜
          </li>
          <li class="">
            <p><i class="iconfont icon-xiyiji"></i></p>
            洗衣机
          </li>
          <li class="">
            <p><i class="iconfont icon-kongdiao"></i></p>
            空调
          </li>
          <li class="">
            <p><i class="iconfont icon-meiqitianranqi"></i></p>
            天然气
          </li>
          <li class="">
            <p><i class="iconfont icon-shuinuanqigongcheng"></i></p>
            暖气
          </li>
          <li class="">
            <p><i class="iconfont icon-dianshiji"></i></p>
            电视
          </li>
          <li class="">
            <p><i class="iconfont icon-haofangtuo400iconfont2reshuiqi"></i></p>
            热水器
          </li>
        </ul>
      </div>

      <!-- <div class="houseCondition"></div> -->
      <div class="houseCondition">
        <div class="conTitle">房源概况</div>
        <div>
          <div class="conPeople">
            <div class="conleft">
              <img src="http://liufusong.top:8080/img/avatar.png" alt="头像" />
              <div class="conName">
                <div>王女士</div>
                <div class="renzhen">
                  <i class="iconfont icon-auth"></i>已认证房主
                </div>
              </div>
            </div>
            <span class="conButton">发消息</span>
          </div>
          <div class="conText">
            1.周边配套齐全，地铁四号线陶然亭站，交通便利，公交云集，距离北京南站、西站都很近距离。
            2.小区规模大，配套全年，幼儿园，体育场，游泳馆，养老院，小学。
            3.人车分流，环境优美。
            4.精装两居室，居家生活方便，还有一个小书房，看房随时联系。
          </div>
        </div>
      </div>

      <div class="youLike">
        <div class="liketitle">猜你喜欢</div>
        <div class="likeList">
          <div class="like-item">
            <div class="likeimg">
              <img src="http://liufusong.top:8080/img/message/1.png" alt="" />
            </div>
            <div class="like-text">
              <h3>安贞西里 3室1厅</h3>
              <div class="text2">72.32㎡/南 北/低楼层</div>
              <div>
                <span class="like-chara">随时看房</span>
              </div>
              <div class="like-price"><span class="">4500</span> 元/月</div>
            </div>
          </div>

          <div class="like-item">
            <div class="likeimg">
              <img src="http://liufusong.top:8080/img/message/2.png" alt="" />
            </div>
            <div class="like-text">
              <h3>天居园 2室1厅</h3>
              <div class="text2">83㎡/南/高楼层</div>
              <div>
                <span class="like-chara">近地铁</span>
              </div>
              <div class="like-price"><span class="">7200</span> 元/月</div>
            </div>
          </div>

          <div class="like-item">
            <div class="likeimg">
              <img src="http://liufusong.top:8080/img/message/3.png" alt="" />
            </div>
            <div class="like-text">
              <h3>角门甲4号院 1室1厅</h3>
              <div class="text2">52㎡/西南/低楼层</div>
              <div>
                <span class="like-chara">集中供暖</span>
              </div>
              <div class="like-price"><span class="">4300</span> 元/月</div>
            </div>
          </div>
        </div>
      </div>

      <div class="foot-bar">
        <div class="btn1">
          <van-icon name="star-o" />
          <span class="">收藏</span>
        </div>
        <div class="btn2">在线咨询</div>
        <div class="btn3">
          <a href="tel:400-618-4000" class="btn3">电话预约</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'housedetail-page',
  async created() {
    const res = await axios.get(
      'http://liufusong.top:8080/houses/' + this.houseCode
    )
    console.log(res.data.body)
    this.houseInfo = res.data.body
    this.longitude = res.data.body.coord.longitude
    this.latitude = res.data.body.coord.latitude
    this.community = res.data.body.community
    console.log(this.longitude, this.latitude)
  },
  async mounted() {
    const res = await axios.get(
      'http://liufusong.top:8080/houses/' + this.houseCode
    )

    const { BMapGL } = window
    const map = new BMapGL.Map('container')
    // const obj = JSON.parse(window.localStorage.getItem('cinfo'))
    // 设置地图中心点
    // const cityName = obj ? obj.label + '市' : '北京市'
    // const cityValue = obj ? obj.value : 'AREA|88cff55c-aaa4-e2e0'
    // console.log(cityName)
    // map.centerAndZoom(cityName, 12) // 初始化地图,设置中心点坐标和地图级别
    // map.enableScrollWheelZoom(true) // 开启鼠标滚轮缩放

    const point = new BMapGL.Point(
      res.data.body.coord.longitude,
      res.data.body.coord.latitude
    )
    console.log(point)
    map.centerAndZoom(point, 12)

    const label = new BMapGL.Label(res.data.body.community, {
      // 创建文本标注
      position: point, // 设置标注的地理位置
      offset: new BMapGL.Size(10, 20) // 设置标注的偏移量
    })
    map.addOverlay(label) // 将标注添加到地图中
  },
  data() {
    return {
      houseCode: localStorage.getItem('houseCode'),
      houseInfo: {},
      longitude: '',
      latitude: '',
      community: ''
    }
  }
}
</script>

<style scoped lang="less">
.whole {
  background-color: #f5f5f9;
  font-size: 14px;
  padding-bottom: 50px;
}
.city-head {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: white;
  height: 252px;
  margin-top: 46px;

  > img {
    width: 100%;
    height: 100%;
  }
}

.houseDetail-info {
  padding: 15px;
  background-color: #fff;

  h3 {
    font-weight: 400;
    font-size: 16px;
    color: #333;
    margin: 16px 0;
  }

  .chara {
    .hao {
      display: inline-block;
      font-size: 12px;
      border-radius: 3px;
      padding: 4px 5px;
      margin-right: 5px;
      line-height: 12px;
      color: #39becd;
      background: #e1f5f8;
    }
  }
  .housePrice {
    height: 84px;
    padding: 15px 0;
    margin: 15px 0;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    border-top: 1px solid #cecece;
    border-bottom: 1px solid #cecece;

    .price-item {
      text-align: center;
      font-family: 'Microsoft YaHei';
      p {
        height: 26px;
        line-height: 26px;
        color: #fa5741;
        font-size: 18px;
        font-weight: bolder;
        width: 110px;
      }
      span {
        font-size: 12px;
        font-weight: 400;
      }
      div {
        height: 26px;
        line-height: 26px;
        font-size: 14px;
        color: #999;
      }
    }
  }
  .houseChara {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    height: 52px;
    width: 100%;

    .houseChara-item {
      width: calc(50%);
      font-size: 13px;
      font-family: 'Microsoft YaHei';
      div {
        color: #333;
        span {
          color: #999;
          padding-right: 5px;
          line-height: 26px;
        }
      }
    }
  }
}

.houseDetail-map {
  margin-top: 10px;
  background-color: #fff;

  .mapTitle {
    margin: 0 3%;
    line-height: 44px;
    font-size: 14px;
    color: #333;
  }

  #container {
    width: 100vw;
    height: 145px;
    overflow: hidden;
    position: relative;
    z-index: 0;
  }
}

.housePei {
  margin-bottom: 10px;
  padding: 0 10px;
  background: #fff;

  .peititle {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 10px;
    padding: 15px 0;
    border-bottom: 1px solid #cecece;
  }
  ul {
    display: flex;
    flex-wrap: wrap;
    text-align: center;
    background: #fff;
    height: 140px;

    li {
      margin: 10px 0;
      width: 20%;
      line-height: 23px;

      p {
        i {
          font-size: 23px;
        }
      }
    }
  }
}

.houseCondition {
  margin: 10px 0;
  padding: 0 10px;
  line-height: 150%;
  background: #fff;
  .conTitle {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 10px;
    padding: 15px 0;
    border-bottom: 1px solid #cecece;
  }

  .conPeople {
    position: relative;
    .conleft {
      margin-bottom: 10px;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      img {
        width: 52px;
        height: 52px;
        margin: 10px 10px 0 0;
      }

      .conName {
        padding: 15px 0 0 5px;

        .renzhen {
          font-size: 12px;
          color: #fa5741;
        }
      }
    }
  }

  .conText {
    line-height: 1.6;
    padding: 10px 0;
    color: #333;
    font-size: 14px;
  }

  .conButton {
    position: absolute;
    right: 15px;
    top: 20px;
    color: #33be85;
    border: 1px solid #33be85;
    border-radius: 3px;
    padding: 3px 15px;
  }
}

.youLike {
  margin: 10px 0 0;
  padding: 0 15px;
  background: #fff;

  .liketitle {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 10px;
    padding: 15px 0;
    border-bottom: 1px solid #cecece;
  }
  .likeList {
    .like-item {
      height: 120px;
      position: relative;
      box-sizing: border-box;
      justify-content: space-around;
      padding-top: 18px;
      border-bottom: 1px solid #e5e5e5;

      .likeimg {
        float: left;
        width: 106px;
        height: 80px;

        img {
          width: 106px;
          height: 80px;
        }
      }

      .like-text {
        overflow: hidden;
        line-height: 22px;
        padding-left: 12px;

        h3 {
          text-overflow: ellipsis;
          white-space: nowrap;
          vertical-align: middle;
          font-size: 15px;
          color: #394043;
        }
        .text2 {
          font-size: 12px;
          color: #afb2b3;
        }
        .like-chara {
          color: #39becd;
          background: #e1f5f8;
          display: inline-block;
          font-size: 12px;
          border-radius: 3px;
          padding: 4px 5px;
          margin-right: 5px;
          line-height: 12px;
        }

        .like-price {
          font-size: 12px;
          color: #fa5741;

          span {
            font-size: 16px;
            font-weight: bolder;
          }
        }
      }
    }
  }
}

.foot-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  line-height: 50px;
  border-top: 1px solid #cecece;
  text-align: center;
  font-size: 17px;
  color: #999;
  background-color: #fff;
  display: flex;
  justify-content: space-evenly;

  .btn1 {
    width: 33%;

    span {
      margin-left: 6px;
    }
  }

  .btn2 {
    width: 33%;
    border-left: 1px solid #e8e8e9;
    text-align: center;
  }

  .btn3 {
    width: 33%;
    // margin-left: 8px;
    a {
      width: 100%;
      height: 50px;
      background-color: #21b97a;
      border-right: 1px solid #e8e8e9;
      // background: transparent;
      display: block;
      text-decoration: none;
      // overflow: hidden;
      color: white;
    }
  }
}
</style>
